package com.woniuxy.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.woniuxy.entity.User;

@Mapper
public interface UserMapper {
	//查询所有用户
	@Select("select * from t_user")
	public List<User> findAllUser();
	//根据用户id查询角色id
	@Select("select rid from t_user_role where uid=#{uid}")
	public List<Integer>findRidByUid(int uid);
	//根据角色id角色name
	@Select("select rname from t_role where rid=#{rid}")
	public String findRnameByRid(int pid);
	//根据状态查询用户
	@Select("select * from t_user where status=#{status}")
	public List<User>findUserByStatus(int status);
	//模糊查询
	@Select("select * from t_user where uname like CONCAT('%',#{words},'%') or account like CONCAT('%',#{words},'%')")
	public List<User>findUserByWords(String words);
	//新建用户
	@Insert("insert into t_user values(default,#{rname},#{rcode},#{status},#{description},#{ctime})")
	public int insertUser(User user);
	//根据uid查询用户
	@Select("select * from t_user where uid=#{uid}")
	public User findUserByUid(int uid);
	//修改密码
	@Update("update t_user1 set pwd=#{pwd} where account=#{account}")
	public int changePwd(User user);
	//根据账户名查询用户（登录
	@Select("select * from t_user1 where account=#{account}")
	public User findUserByAccount(String account);
	//删除角色
	@Delete("delete from t_user where uid=#{uid}")
	public int delByUid(int uid);
}